﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using NCMIS.Client;

namespace Ncmis.Client.Explorer
{
    /// <summary>
    /// Interaction logic for LoginWindow.xaml
    /// </summary>
    public partial class LoginWindow : Window
    {
        public LoginWindow()
        {
            InitializeComponent();
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            // TODO: Check that the URI is not empty and valid URI
            string userName = usernameTextBox.Text;
            string password = passwordBox.Password;
            string uriString = serviceTextBox.Text;
            try
            {
                this.Cursor = Cursors.Wait;
                ((MainWindow)this.Owner).CmisWebRequest = new CmisWebRequest(userName, password, new Uri(uriString));
                ((MainWindow)this.Owner).PopulateServiceDocument();
                ((MainWindow)this.Owner).InitializeGui();
                this.Cursor = Cursors.Arrow;
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Login failed. ({0})", ex.Message));
            }
        }
    }
}
